package com.example.demo.controller;

import com.example.demo.domain.Result;
import com.example.demo.domain.User;
import com.example.demo.domain.dto.EditUserDTO;
import com.example.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/avatar/{username}")
    public Result getAvatar(@PathVariable String username) {
        System.out.println(username);
        return Result.ok("https://pixnio.com/free-images/2025/02/11/2025-02-11-05-23-44-576x763.jpg");
    }

    @PostMapping("/edit")
    public Result geUser(@RequestBody EditUserDTO editUser) {
        System.out.println(editUser);
        boolean check = userService.EditUserInfo(editUser);

        return check ? Result.ok() : Result.error();
    }

    @GetMapping("/getUser")
    public Result getUser(Integer id) {
        User user = userService.getById(id);
        return user != null ? Result.ok(user) : Result.error();
    }
}
